import 'package:cms/models/term.dart';
import 'package:cms/state/lara_press_cms/lara_press_cms_cubit.dart';
import 'package:cms/state/lara_press_cms/lara_press_cms_state.dart';
import 'package:common/export/get_it.dart';
import 'package:common/export/bloc.dart';
import 'package:flutter/material.dart';

import 'home_state_state.dart';

class HomeStateCubit extends Cubit<HomeStateState> {
  final TickerProvider? tickerProvider;
  HomeStateCubit({this.tickerProvider}) : super(HomeStateState().init()) {
    homeInit();
  }

  void homeInit() {
    LaraPressCmsState laraPressCmsState =
        laraPressGetIt<LaraPressCmsCubit>().state;
    List<WpTerm> homeShowCategory =
        laraPressCmsState.configuration?.homeShowCategory ?? [];
    TabController tabController = TabController(
      length: homeShowCategory.length,
      vsync: tickerProvider!,
    );
    emit(
      state.copyWith(
        tabController: tabController,
        homeShowCategory: homeShowCategory,
      ),
    );
  }
}
